<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.hilaver.dzmis.Constants"%>
<%@ page import="com.hilaver.dzmis.service.impl.CtServiceImpl"%>
<%@ page
	import="com.hilaver.dzmis.service.impl.ProductPackageServiceImpl"%>
<%@ page import="com.hilaver.dzmis.service.impl.I18nServiceImpl"%>
<%@ page import="com.hilaver.dzmis.procurement.ProductPackage"%>
<%@ page import="com.hilaver.dzmis.product.ProductIdentification"%>
<%@ page import="com.hilaver.dzmis.procurement.ProductPackageItem"%>
<%@ page import="com.hilaver.dzmis.util.StringUtils"%>
<%
	Integer id = Integer.parseInt(request.getParameter("id"));
	ProductPackageServiceImpl pps = new ProductPackageServiceImpl();
	Locale locale = (Locale) request.getSession().getAttribute(
			Constants.SESSION_LOCALE);
	I18nServiceImpl i18n = new I18nServiceImpl();
	ProductPackage pp = pps.getObj(id);
	Set<ProductIdentification> piSet = pp.getProductIndentifications();
	//List<ProductPackageItem> ppiList = pps.getPackageItemListAll(id);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
<link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
<style type="test/css">

</style>
<title><%=pp.getName() %></title>
</head>
<body>
<table cellspacing="0" id="the-table" style="width: 100%;">
	<tbody>
		<tr>
			<td width="33%">
				<b><%=i18n.getShortMessage(locale, "ui.package.packagelist")%>&nbsp;(&nbsp;<%=pp.getUnit()%>&nbsp;<%=i18n.getShortMessage(locale, "ui.package.unit")%>&nbsp;)</b>
			</td>
			<td width="33%">
				<b><%=i18n.getShortMessage(locale, "ui.package.createtime")%>(m/d/Y):&nbsp;&nbsp;<%=StringUtils.toString(pp.getCreateTime())%></b>
			</td>
			<td>
				<b><%=i18n.getShortMessage(locale, "ui.package.invoice")%>:&nbsp;&nbsp;<%=pp.getInvoiceNumber()%></b>
			</td>
		</tr>
		<tr>
			<td width="33%" style="text-align: center;">
				<b><%=i18n.getShortMessage(locale, "ui.package.consignor")%></b>
			</td>
			<td width="33%" style="text-align: center;">
				<b><%=i18n.getShortMessage(locale, "ui.package.recipient")%></b>
			</td>
			<td style="text-align: center;">
				<b><%=i18n.getShortMessage(locale, "message.edit.customername")%></b>
			</td>
		</tr>
		<tr>
			<td width="33%" style="text-align: center;">
				<b><%=pp.getConsignor()%></b>
			</td>
			<td width="33%" style="text-align: center;">
				<b><%=pp.getRecipient()%></b>
			</td>
			<td style="text-align: center;">
				<b><%=pp.getBiFranceCustomer().getName()%></b>
			</td>
		</tr>
	</tbody>
</table>
<br>
<% for(ProductIdentification pi : piSet){ 
		List<ProductPackageItem> ppiList = pps.getPackageItemListFrom(pi);
		if(ppiList.size() > 1){
%>
<table cellspacing="0" id="the-table" style="width: 100%;">
	<tr>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			<%=i18n.getShortMessage(locale, "ui.productidentification.ordernumber") %>
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			<%=i18n.getShortMessage(locale, "ui.reference.reference") %>
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			<%=i18n.getShortMessage(locale, "ui.productidentification.yarnnumber") %>
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			<%=i18n.getShortMessage(locale, "ui.productidentification.color") %>
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			<%=i18n.getShortMessage(locale, "ui.package.packagenumber") %>
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			<%=i18n.getShortMessage(locale, "ui.package.choice") %>
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			<%=i18n.getShortMessage(locale, "ui.package.standard") %>
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			S
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			M
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			L
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			XL
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			XXL
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			XXXL
		</td>
		<td style="background:#eeeeee;text-align: center;font-weight: bold;">
			<%=i18n.getShortMessage(locale, "ui.package.total") %>
		</td>
	</tr>
	<%	int i;
		int sTotal = 0;
	   	int mTotal = 0;
	   	int lTotal = 0;
	   	int xlTotal = 0;
	   	int xxlTotal = 0;
	   	int xxxlTotal = 0;
	   	int total = 0;
		for(i = 0; i < ppiList.size(); i ++){ 
		ProductPackageItem ppi = ppiList.get(i);
	%>
	<tr <%
		if(i != ppiList.size() - 1 && ppi.getPackageNumber().equals(ppiList.get(i + 1).getPackageNumber())){
			out.print("style=\"background-color: #eeeeee;\"");
		}
		if(i != 0 && ppi.getPackageNumber().equals(ppiList.get(i - 1).getPackageNumber())){
			out.print("style=\"background-color: #eeeeee;\"");
		}
	%>>
		<% if(i ==0){ %>
			<td style="text-align: center; width: 100px;vertical-align: top;background-color: white;" rowspan="<%=ppiList.size() %>">
				<%=ppi.getOrderNumber() %>
			</td>
			<td style="text-align: center; width: 100px;vertical-align: top;background-color: white;" rowspan="<%=ppiList.size() %>">
				<%=ppi.getReference()%>
			</td>
			<td style="text-align: center; width: 100px;vertical-align: top;background-color: white;" rowspan="<%=ppiList.size() %>">
				<%=ppi.getYarnName()%>
			</td>
		<% } %>
		<td style="text-align: center;">
			<%=ppi.getColor() %>
		</td>
		<td style="text-align: center;">
			<%=ppi.getPackageNumber() %>
		</td>
		<td style="text-align: center;width: 100px;">
			<%=ppi.getChoice() %>
		</td>
		<td style="text-align: center;">
			<%=ppi.getStandard() %>
		</td>
		<td style="text-align: center;">
			<% if(ppi.getAmountS() != null){
					sTotal += ppi.getAmountS();
					out.print( ppi.getAmountS());
				}
			%>
		</td>
		<td style="text-align: center;">
			<% if(ppi.getAmountM() != null){
					mTotal += ppi.getAmountM();
					out.print( ppi.getAmountM());
				}
			%>
		</td>
		<td style="text-align: center;">
			<% if(ppi.getAmountL() != null){
					lTotal += ppi.getAmountL();
					out.print( ppi.getAmountL());
				}
			%>
		</td>
		<td style="text-align: center;">
			<% if(ppi.getAmountXl() != null){
					xlTotal += ppi.getAmountXl();
					out.print( ppi.getAmountXl());
				}
			%>
		</td>
		<td style="text-align: center;">
			<% if(ppi.getAmountXxl() != null){
					xxlTotal += ppi.getAmountXxl();
					out.print( ppi.getAmountXxl());
				}
			%>
		</td>
		<td style="text-align: center;">
			<% if(ppi.getAmountXxxl() != null){
					xxxlTotal += ppi.getAmountXxxl();
					out.print( ppi.getAmountXxxl());
				}
			%>
		</td>
		<td style="text-align: center;">
			<% if(ppi.getPackageAmount() != null){
					total += ppi.getPackageAmount();
					out.print( ppi.getPackageAmount());
				}
			%>
		</td>
	</tr>
	<%} %>
	<tr style="font-weight: bold;color: red;">
		<td style="text-align: right;" colspan="4">
			<%=i18n.getShortMessage(locale, "ui.package.totalpackage") %>
			&nbsp;&nbsp;
		</td>
		<td style="text-align: center;">
			<%=ppiList.get(i-1).getPackageNumber() %>
		</td>
		<td style="text-align: right;" colspan="2">
			<%=i18n.getShortMessage(locale, "message.list.total") %>
			&nbsp;&nbsp;
			<%=ppiList.get(i-1).getOrderNumber() %>
			&nbsp;&nbsp;
		</td>
		<td style="text-align: center;">
			<%=sTotal %>
		</td>
		<td style="text-align: center;">
			<%=mTotal %>
		</td>
		<td style="text-align: center;">
			<%=lTotal %>
		</td>
		<td style="text-align: center;">
			<%=xlTotal %>
		</td>
		<td style="text-align: center;">
			<%=xxlTotal %>
		</td>
		<td style="text-align: center;">
			<%=xxxlTotal %>
		</td>
		<td style="text-align: center;">
			<%=total %>
		</td>
	</tr>
</table>
<br/>
<%}
} %>
</body>
</html>